package controller.teacher.manager;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import controller.ServletBase;

import dao.Teacher;

public class Base extends ServletBase {
    private static final long serialVersionUID = 1L;

    public Base() {
        super();
    }

    protected boolean doInit(HttpServletRequest request,
            HttpServletResponse response) {
        super.doInit(request, response);
        HttpSession session = request.getSession();
        String type = (String) session.getAttribute("user-type");
        try {
            Teacher.Data d = (Teacher.Data) session.getAttribute("user-data");
            if (d != null && type.equals("teacher")) {
                request.setAttribute("title", d.getName());
                request.setAttribute("id", d.getId());
                request.setAttribute("no", d.getNo());
                request.setAttribute("name", d.getName());
                request.setAttribute("pwd", d.getPassword());
                view.display("teacher/head.jsp");
                return true;
            } else {
                view.sendRedirect(request.getContextPath() + "/login");
                return false;
            }
        } catch (ClassCastException e) {
            return false;
        }
    }

    protected boolean doEnd(HttpServletRequest request,
            HttpServletResponse response) {
        view.display("common/foot.jsp");
        return true;
    }
}
